package com.my.control.validate
{
	import com.my.commons.constants.ConstVars;
	import com.my.view.popup.AlterPassView;
	
	import mx.core.UIComponent;
	
	public class AlterPassValidate extends AbstractValidate implements IValidate
	{
		public function AlterPassValidate(value:UIComponent)
		{
			super(value);
		}
		
		public override function validate():Boolean{
			var bool1 : Boolean = usernameValidate();
			var bool2 : Boolean = oldPassValidate();
			var bool3 : Boolean = newPassValidate();
			var bool4 : Boolean = verifyPassValidate();
			var bool5 : Boolean = codeValidate();
			
			return bool1 && bool2 && bool3 && bool4 && bool5;
		}
		
		private function usernameValidate():Boolean{
			if(getView().username.text.match(ConstVars.NAME_REGEX)){
				getView().usernameTip.text = "";
				return true;
			}else{
				getView().usernameTip.text = ConstVars.NAME_TIP;
				return false;
			}
		}
		private function oldPassValidate():Boolean{
			if(getView().oldPass.text.match(ConstVars.PASS_REGEX)){
				getView().oldPassTip.text = "";
				return true;
			}else{
				getView().oldPassTip.text = ConstVars.PASS_TIP;
				return false;
			}
		}
		private function newPassValidate():Boolean{
			if(getView().newPass.text.match(ConstVars.PASS_REGEX)){
				getView().newPassTip.text = "";
				return true;
			}else{
				getView().newPassTip.text = ConstVars.PASS_TIP;
				return false;
			}
		}
		private function verifyPassValidate():Boolean{
			if(getView().verifyPass.text.match(ConstVars.PASS_REGEX) && getView().newPass.text == getView().verifyPass.text){
				getView().verifyPassTip.text = "";
				return true;
			}else{
				getView().verifyPassTip.text = ConstVars.PASS_TIP;
				return false;
			}
		}
		private function codeValidate():Boolean{
			if(getView().code.text.match(ConstVars.CODE_REGEX)){
				getView().codeTip.text = "";
				return true;
			}else{
				getView().codeTip.text = ConstVars.CODE_TIP;
				return false;
			}
		}
		
		
		public function getView():AlterPassView{
			return AlterPassView(view);
		}
	}
}